1 module firecracker_d.core.client;
2 import requests;
3 import firecracker_d.models.client_models;
4 import firecracker_d.core.transport;
5 import std.json;
6 
7 /***
8 * The base class for our API requests
9 ***/
10 class FirecrackerAPIClient {
11 	private {
12 		Request rq;
13 		UnixStream factory;
14 	}
15 
16 	/***
17 	* Do an HTTP PUT to the Firecracker server with a given path
18 	***/
19 	Response put(string path, string model) {
20 		Response r = rq.exec!"PUT"("http://localhost" ~ path, model);
21 		return r;
22 	}
23 
24 	/***
25 	* Do an HTTP PATCH to the firecracker server with a given path
26 	***/
27 	Response patch(string path, string model) {
28 		Response r = rq.exec!"PATCH"("http://localhost" ~ path, model);
29 		return r;
30 	}
31 
32 	/***
33 	* Do an HTTP GET to the Firecracker server with a given path
34 	***/
35 	Response get(string path, string query = "") {
36 		Response r;
37 		if(query != "") {
38 			r = rq.exec!"GET"("http://localhost" ~ path, query);
39 		}
40 		else {
41 			r = rq.exec!"GET"("http://localhost" ~ path);
42 		}
43 		return r;
44 	}
45 
46 	/***
47 	* Construct a new instance of the object with the path to the Firecracker's UNIX Socket
48 	***/
49 	this(string socketPath) {
50 		rq = Request();
51 		factory = new UnixStream();
52 		factory.setFactorySocket(socketPath);
53 		rq.socketFactory = &factory.dg;
54 		rq.addHeaders(["Content-Type": "application/json"]);
55 	}
56 }
57 
58